package com.monitor.interceptor;

import java.util.Map;

import org.apache.log4j.Logger;

import com.monitor.po.Administrator;
import com.monitor.po.User;
import com.monitor.util.Constants;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * @author zzy
 * @catagory
 */
public class UserAuthInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = -6448836636785580845L;
	private static final Logger logger = Logger.getLogger(UserAuthInterceptor.class);

	@Override
	public String intercept(ActionInvocation actionInvocation) throws Exception {
		Map<String, Object> session = actionInvocation.getInvocationContext().getSession();
		Object sessionUser = session.get(Constants.SESSION_USER);
		if (sessionUser != null) {
			if ((sessionUser instanceof Administrator) || (sessionUser instanceof User)) {
				return actionInvocation.invoke();
			}
		}
		logger.info("UserAuthInterceptor -- 没有登陆!");
		return "global";

	}
}
